package org.swan.web.exception;

import org.stream.base.MessageBean;

public class BusinessException extends RuntimeException {
    private final int code;
    private final String description;

    private final Object data;

    public BusinessException(BusinessCode businessCode) {
        this(businessCode, null);
    }

    public BusinessException(BusinessCode businessCode, Object data) {
        this.code = businessCode.getCode();
        this.description = businessCode.getDescription();
        this.data = data;
    }

    public final MessageBean<Object> toMessageBean() {
        return new MessageBean<>(code, description, data);
    }
}
